package com.dingpeikeji.quickdeer.modules.rentproduct.web;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;

import java.text.Format;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dingpeikeji.quickdeer.core.common.persistence.Page;
import com.dingpeikeji.quickdeer.core.common.utils.DateUtils;
import com.dingpeikeji.quickdeer.core.common.web.BaseController;
import com.dingpeikeji.quickdeer.core.modules.cupons.entity.CuponsInfo;
import com.dingpeikeji.quickdeer.core.modules.cupons.service.TCuponsService;
import com.dingpeikeji.quickdeer.core.modules.line.entity.TLine;
import com.dingpeikeji.quickdeer.core.modules.line.service.TLineService;
import com.dingpeikeji.quickdeer.core.modules.orders.entity.TOrders;
import com.dingpeikeji.quickdeer.core.modules.orders.service.TOrdersService;
import com.dingpeikeji.quickdeer.core.modules.site.entity.TSitedtl;
import com.dingpeikeji.quickdeer.core.modules.site.service.TSitedtlService;
import com.dingpeikeji.quickdeer.core.modules.sys.entity.Office;
import com.dingpeikeji.quickdeer.core.modules.sys.entity.User;
import com.dingpeikeji.quickdeer.core.modules.sys.service.OfficeService;
import com.dingpeikeji.quickdeer.core.modules.sys.utils.UserUtils;
import com.dingpeikeji.quickdeer.mobile.service.OrderService;
import com.dingpeikeji.quickdeer.modules.base.service.FrontUserService;
import com.dingpeikeji.quickdeer.modules.base.web.FSysController;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.ProRentOrders;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.ShareRentproduct;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TCargotype;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TCargotypeForsale;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TDemands;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TRentgroup;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TRentproduct;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.FRentproductService;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.RentproductOrderService;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.ShareProductService;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.TCargotypeService;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.TRentgroupService;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.TRentproductService;
import com.dingpeikeji.quickdeer.modules.utils.ValidateCodeTool;
import com.dingpeikeji.quickdeer.modules.utils.ValidateTool;
import com.dingpeikeji.quickdeer.utils.BackResult;
import com.dingpeikeji.quickdeer.utils.UUIDUtils;
import com.google.common.collect.Lists;

/**
 * AA拼车
 */
@Controller
@RequestMapping(value = "${adminPath}/orders/shareProduct")
public class TShareRentController extends BaseController {

	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	Format f = new SimpleDateFormat("E");
	
	@Autowired
	private TRentproductService tRentproductService;
	@Autowired
	private TSitedtlService tSitedtlService;
	@Autowired
	private FRentproductService rentproductService;
	@Autowired
	private TRentgroupService tRentgroupService;
	@Autowired
	private TCuponsService tCuponsService;
	@Autowired
	private TCargotypeService cargotypeService;
	@Autowired
	private FrontUserService frontUserService;
	@Autowired
	private ShareProductService shareProductService;
	@Autowired
	private RentproductOrderService rentproductOrderService;
	@Autowired
	private TOrdersService tOrdersService;
	@Autowired
	private TLineService tLineService;
	@Autowired
	private TCargotypeService tCargotypeService;
	@Autowired 
	private OfficeService officeService;
	//拼车列表
	@RequestMapping(value = "allShareList")
	public String getShareList(HttpServletRequest request,HttpServletResponse response, Model model,
			ShareRentproduct shareRentproduct){
		shareRentproduct.setType("1");
		Page<ShareRentproduct> page = shareProductService.findPage(new Page<ShareRentproduct>(request, response), shareRentproduct);
		model.addAttribute("shareRentproduct", shareRentproduct);
		model.addAttribute("page", page);

		return "modules/orders/shareProductList";
	}
	//过期拼车
	@RequestMapping(value = "expireShareList")
	public String expireShareList(HttpServletRequest request,HttpServletResponse response, Model model,
			ShareRentproduct shareRentproduct){
		Page<ShareRentproduct> page = shareProductService.findDelPage(new Page<ShareRentproduct>(request, response), shareRentproduct);
		model.addAttribute("shareRentproduct", shareRentproduct);
		model.addAttribute("page", page);
		
		return "modules/orders/expireProductList";
	}
	//拼车详情
	@RequestMapping(value = "shareForm")
	public String shareForm( Model model,String sid){
		ShareRentproduct shareRentproduct = shareProductService.getElseInfo(sid);
		model.addAttribute("shareRentproduct", shareRentproduct);
		model.addAttribute("office", shareRentproduct.getOffice().getName());
		if(shareRentproduct.gettCargotype()!=null){
			model.addAttribute("cartype", shareRentproduct.gettCargotype().getTypename());
		}
		return "modules/orders/shareProductForm";
	}
	//添加拼车
	@RequestMapping(value = "addShareProduct")
	public String addShareProduct(RedirectAttributes redirectAttributes, Model model,HttpServletRequest request,ShareRentproduct shareRentproduct,String type){
		if(type==null){
			type=(String) request.getAttribute("type");
		}
		TLine line = new TLine();
		line.setLinestatus(TLine.LINESTATUS_VALID);
		line.setLinetype(TLine.LINE_TYPE_TRAVEL);
		List<TLine> lineList = tLineService.findList(line);
		model.addAttribute("lineList", lineList);
		List<TCargotype> cargotypeList = tCargotypeService.findList(new TCargotype());
		//List<TCargotype> cargotypeList = tCargotypeService.findalltypes();
		model.addAttribute("cargotypeList", cargotypeList);
		if(type==null||type.equals("0")){
			return "modules/orders/addShareProductForm";
		}else if(type.equals("1")){
			return "modules/orders/addJsjShareProductForm";
		}else{
			return "modules/orders/addCjShareProductForm";
		}
	}
	
	//发布旅游拼车
		@RequestMapping(value = "lvCar",method = RequestMethod.POST)
		public String lvCar( Model model,String lineid,String fromdate,String boardaddr, RedirectAttributes redirectAttributes,
				HttpServletRequest request,String enddate,String minamount,String maxamount,String allprice,String payertel,String contacts,String cargotypeid) throws Exception{
			//根据提交的车型id,获取车型信息
			TLine line =tLineService.get(lineid);
			User user = UserUtils.getUser();
			Date fromDate = DateUtils.parseDate(fromdate);
			Date endDate = DateUtils.parseDate(enddate);
			if(fromDate.before(new Date())||endDate.before(new Date())){
				redirectAttributes.addFlashAttribute("message", "出发或截止时间必须大于当前时间");
				return "redirect:addShareProduct";
			}
			if (fromDate.before(endDate)) {
				redirectAttributes.addFlashAttribute("message", "截止时间不能小于出发时间");
				return "redirect:addShareProduct";
			}
			//校验拼车总人数和车型核载人数
			if (Integer.parseInt(minamount) > Integer.parseInt(maxamount)) {
				redirectAttributes.addFlashAttribute("message", "拼车人数不能超过车辆核载人数");
				return "redirect:addShareProduct";
			}
			//计算价格
			double realPrice = 0;
			ShareRentproduct shareRentproduct = new ShareRentproduct();
			realPrice = Double.parseDouble(allprice);//t.getSuitrtnprice();
			//根据人数计算平均价格
			double avgPrice = Math.round(realPrice / Integer.parseInt(minamount));
			//初始化shareProduct
			shareRentproduct.setSid(UUIDUtils.getId().substring(0, 10));
			shareRentproduct.setOfficeId(user.getOffice().getId());//rentgroup.getOffice().getId()
			shareRentproduct.setProductname(line.getLinename()+line.getEstdays()+""+"日拼车");
			shareRentproduct.setCreateBy(user);
			shareRentproduct.setCreateDate(new Date());
			shareRentproduct.setMaxamount(maxamount);//car.getSeats()+""
			shareRentproduct.setMinamount(minamount);
			shareRentproduct.setDaysnum(line.getEstdays()+"");//rentgroup.getDaysnum()+""
			shareRentproduct.setCargotype(cargotypeid);
			shareRentproduct.setPurchasenum("1");//拼车只能为1
			shareRentproduct.setFromdate(fromDate);
			shareRentproduct.setEnddate(endDate);
			shareRentproduct.setBoardaddr(boardaddr);
			shareRentproduct.setPhone(payertel);
			shareRentproduct.setContacts(contacts);
			shareRentproduct.setAvgprice(avgPrice);
			shareRentproduct.setCurrentsell(0);//初始化已购买人数
			shareRentproduct.setTotalprice(realPrice);//使用优惠券之后的价格
			shareRentproduct.setStatus("1");
			shareRentproduct.setSharetype(ShareRentproduct.SHARE_TYPE_AIR);
			shareRentproduct.setDepartsite(line.getDepartcity().getSiteid());
			shareRentproduct.setDestsite(line.getDestcity().getSiteid());
			shareRentproduct.setLinepic(line.getLinepic());
			//插入数据
			int result = shareProductService.insert(shareRentproduct);
			if (result > 0) {
				redirectAttributes.addFlashAttribute("message", "生成拼车成功");
				return "redirect:allShareList";
			}else{
				redirectAttributes.addFlashAttribute("message", "生成拼车失败");
				return "redirect:addShareProduct";
			}
		}
		
		/**
		 *发布接送机拼车
		 */
		@RequestMapping(value = "jsjCar",method = RequestMethod.POST)
		@Transactional
		public String list( Model model,String userid,ShareRentproduct shareRentproduct, RedirectAttributes redirectAttributes, String jsjtype,String before,String end,
				HttpServletResponse response, HttpServletRequest request,String maxamount,String allprice,String mapkm,String maptime,TCargotypeForsale cargotypeForsale,
				String every,String Mon,String Tue,String Wed,String Thu,String Fri,String Sat,String Sun,String deptime) {
			Date beforeday=DateUtils.parseDate(before);
			Date endday=DateUtils.parseDate(end);
			int during=(int)DateUtils.getDistanceOfTwoDate(beforeday, endday)+1;
			request.setAttribute("type", "1");
			model.addAttribute("type", "1");
			TSitedtl depart =new TSitedtl();
			depart.setSiteid(shareRentproduct.getDepartsite());
			depart.setSitename(request.getParameter("departsitename"));
			TSitedtl dest =new TSitedtl();
			dest.setSitename((request.getParameter("destsitename")));
			dest.setSiteid(shareRentproduct.getDepartsite());
			User user = frontUserService.get(UserUtils.getUser().getId());
			if (user==null) {
				redirectAttributes.addFlashAttribute("message", "获取用户信息失败");
				return "redirect:index";
			}
			Office a = officeService.get(user.getOffice().getId());
			//根据提交的车型id,获取车型信息
			TCargotype tCargotype = tCargotypeService.get(shareRentproduct.getCargotype());
			if (tCargotype==null) {
				redirectAttributes.addFlashAttribute("message", "获取车型信息失败");
				return "redirect:addShareProduct?type=1";
			}
			//处理productname
			String productname="";
			if (jsjtype.equals("0")) {
				productname = depart.getSitename()
						+"-"+dest.getSitename()+"(拼车)";
			}else if (jsjtype.equals("1")) {
				productname = dest.getSitename()
						+"-"+depart.getSitename()+"(拼车)";
			}
			
			//根据人数计算平均价格
			double avgPrice = Math.round(Double.parseDouble(allprice) / Integer.parseInt(shareRentproduct.getMinamount()));
			if (avgPrice<=0) {
				redirectAttributes.addFlashAttribute("message", "订单金额不合法");
				return "redirect:addShareProduct?type=1";
			}
			
//			//根据提交的车队name和abbr查询车队
//			String officeId = officeService.findIdByNameAndAbbr(t.getOfficeList().get(0).getName(), t.getOfficeList().get(0).getAbbr());
//			if (StringUtils.isEmpty(officeId)) {
//				redirectAttributes.addFlashAttribute("message", "获取车队信息失败");
//				return "redirect:addShareProduct?type=1";
//			}
			
			//初始化shareProduct
			//shareRentproduct.setSid(UUIDUtils.getId().substring(0,10));
			shareRentproduct.setOfficeId(user.getOffice().getId());
			shareRentproduct.setProductname(productname);
			shareRentproduct.setCreateBy(user);
			shareRentproduct.setCreateDate(new Date());
			shareRentproduct.setMaxamount(maxamount);//t.getCargotype().getSeats()+""
			shareRentproduct.setDaysnum("1");//接送机默认1天
			shareRentproduct.setPurchasenum("1");//拼车只能为1s
			shareRentproduct.setAvgprice(avgPrice);
			shareRentproduct.setCurrentsell(0);//初始化已购买人数
			shareRentproduct.setTotalprice(Double.parseDouble(allprice));//使用优惠券之后的价格
			shareRentproduct.setStatus("1");
			shareRentproduct.setSharetype(ShareRentproduct.SHARE_TYPE_AIR);
			//默认图片
			shareRentproduct.setLinepic("https://www.xiakeyueche.com/userfiles/airport.jpg");
			if(during>1){
				shareRentproduct.setSameid(UUIDUtils.getId().substring(0,8));
			}
			//插入数据
			int result = 0;
			for(int i=0;i<during;i++){
				result=0;
				Date day = new Date();
				Date over = new Date();
				long t1 = (beforeday.getTime()/1000)+60*60*24*i;
				day.setTime(t1*1000);
				String countWeek = f.format(day);
				long t2 = (day.getTime()/1000)-60*60*24;
				over.setTime(t2*1000);
				if(!"1".equals(every)){
					if(countWeek.equals("星期一")&&!"1".equals(Mon)){
						continue;
					}else if(countWeek.equals("星期二")&&!"1".equals(Tue)){
						continue;
					}else if(countWeek.equals("星期三")&&!"1".equals(Wed)){
						continue;
					}else if(countWeek.equals("星期四")&&!"1".equals(Thu)){
						continue;
					}else if(countWeek.equals("星期五")&&!"1".equals(Fri)){
						continue;
					}else if(countWeek.equals("星期六")&&!"1".equals(Sat)){
						continue;
					}else if(countWeek.equals("星期日")&&!"1".equals(Sun)){
						continue;
					}
				}
				shareRentproduct.setSid(UUIDUtils.getId().substring(0,10));
				try {
					shareRentproduct.setFromdate(df.parse(sdf.format(day)+" "+deptime));
					shareRentproduct.setEnddate(df.parse(sdf.format(over)+" 23:59"));
					//System.out.println(df.format(shareRentproduct.getFromdate())+"!!!!!!!!!!"+df.format(shareRentproduct.getEnddate())+"!!!!!!!!!!"+countWeek+"\n");
				} catch (ParseException e) {
					redirectAttributes.addFlashAttribute("message", "时间转换出错");
					return "redirect:addShareProduct?type=1";
				}
				 result=shareProductService.insert(shareRentproduct);
			}
			
			if (result > 0) {
				redirectAttributes.addFlashAttribute("message", "生成拼车成功");
				return "redirect:allShareList";
			}else{
				redirectAttributes.addFlashAttribute("message", "生成拼车失败");
				return "redirect:addShareProduct?type=1";
			}
		}
		
		/**
		 *发布城际拼车
		 */
		@RequestMapping(value = "cjCar",method = RequestMethod.POST)
		@Transactional
		public String cjcar( Model model,ShareRentproduct shareRentproduct, RedirectAttributes redirectAttributes,String before,Integer end,
				HttpServletResponse response, HttpServletRequest request,String maxamount,String allprice,String deptime,String desttime,
				Integer sum,Integer areanum,Integer placenum) {
			String[] area = new String[areanum];
			String[] dep = new String[areanum];
			if(areanum>1){
				area=shareRentproduct.getBoardaddr().split(",");
				dep=deptime.split(",");
				for(int i=0;i<areanum;i++){
					if(area.length<areanum||area[i]==null||area[i]==""){
						redirectAttributes.addFlashAttribute("message", "上车地点填写不全");
						return "redirect:addShareProduct?type=2";
					}
					if(dep.length<areanum||dep[i]==null||dep[i]==""){
						redirectAttributes.addFlashAttribute("message", "上车时间填写不全");
						return "redirect:addShareProduct?type=2";
					}
				}
			}else{
				area[0]=shareRentproduct.getBoardaddr();
				dep[0]=deptime;
			}
			
			String[] place = new String[placenum];
			String[] des = new String[placenum];
			if(placenum>1){
				place=shareRentproduct.getDestaddr().split(",");
				des=desttime.split(",");
				for(int i=0;i<placenum;i++){
					if(place.length<placenum||place[i]==null||place[i]==""){
						redirectAttributes.addFlashAttribute("message", "下车地点填写不全");
						return "redirect:addShareProduct?type=2";
					}
					if(des.length<placenum||des[i]==null||des[i]==""){
						redirectAttributes.addFlashAttribute("message", "下车时间填写不全");
						return "redirect:addShareProduct?type=2";
					}
				}
			}else{
				place[0]=shareRentproduct.getDestaddr();
				des[0]=desttime;
			}
			Date beforeday=DateUtils.parseDate(before);
			request.setAttribute("type", "2");
			model.addAttribute("type", "2");
			TSitedtl depart =new TSitedtl();
			depart.setSiteid(shareRentproduct.getDepartsite());
			depart.setSitename(request.getParameter("departsitename"));
			TSitedtl dest =new TSitedtl();
			dest.setSitename((request.getParameter("destsitename")));
			dest.setSiteid(shareRentproduct.getDepartsite());
			User user = frontUserService.get(UserUtils.getUser().getId());
			if (user==null) {
				redirectAttributes.addFlashAttribute("message", "获取用户信息失败");
				return "redirect:index";
			}
			
			//根据人数计算平均价格
			double avgPrice = Math.round(Double.parseDouble(allprice) / Integer.parseInt(shareRentproduct.getMinamount()));
			if (avgPrice<=0) {
				redirectAttributes.addFlashAttribute("message", "订单金额不合法");
				return "redirect:addShareProduct?type=2";
			}
			
			Date over = new Date();
			long t = (beforeday.getTime()/1000)-60*60*24*end;
			over.setTime(t*1000);
			
			String productname =depart.getSitename()+"-"+dest.getSitename()+"(城际拼车)";
			shareRentproduct.setOfficeId(user.getOffice().getId());
			shareRentproduct.setProductname(productname);
			shareRentproduct.setCreateBy(user);
			shareRentproduct.setCreateDate(new Date());
			shareRentproduct.setMaxamount(maxamount);//t.getCargotype().getSeats()+""
			shareRentproduct.setPurchasenum("1");//拼车只能为1s
			shareRentproduct.setAvgprice(avgPrice);
			shareRentproduct.setCurrentsell(0);//初始化已购买人数
			shareRentproduct.setTotalprice(Double.parseDouble(allprice));//使用优惠券之后的价格
			shareRentproduct.setStatus("1");
			shareRentproduct.setSharetype(ShareRentproduct.SHARE_TYPE_CJ);
			//默认图片
			shareRentproduct.setLinepic("https://www.xiakeyueche.com/userfiles/airport.jpg");
			try {
				shareRentproduct.setEnddate(df.parse(sdf.format(over)+" 23:59"));
			} catch (ParseException e) {
				redirectAttributes.addFlashAttribute("message", "时间转换出错");
				return "redirect:addShareProduct?type=2";
			}
			int result =0;
			for(int i=0;i<sum;i++){//每日班次循环
				for(int j=0;j<areanum;j++){
					for(int z=0;z<placenum;z++){
						shareRentproduct.setSid(UUIDUtils.getId().substring(0,10));
						shareRentproduct.setBoardaddr(area[j]);
						shareRentproduct.setDestaddr(place[z]);
						try {
							shareRentproduct.setFromdate(df.parse(sdf.format(beforeday)+" "+dep[j]));
							shareRentproduct.setOverdate(df.parse(sdf.format(beforeday)+" "+des[z]));
						} catch (ParseException e) {
							redirectAttributes.addFlashAttribute("message", "时间转换出错");
							return "redirect:addShareProduct?type=2";
						}
					    result =shareProductService.insert(shareRentproduct);
						//System.out.println("成功\n");
					}
				}
			}
			if (result > 0) {
				redirectAttributes.addFlashAttribute("message", "生成拼车成功");
				return "redirect:allShareList";
			}else{
				redirectAttributes.addFlashAttribute("message", "生成拼车失败");
				return "redirect:addShareProduct?type=2";
			}
		}
		
}

//			//获取车型
//			TCargotype cargotype = new TCargotype();
//			cargotypeForsale.setCargotype(cargotype);
//			cargotypeForsale.setDepartcity(depart);
//			cargotypeForsale.setDestcity(dest);
//			//判断出发日期和截止日期
//			if(shareRentproduct.getFromdate().before(new Date())||shareRentproduct.getEnddate().before(new Date())){
//				redirectAttributes.addFlashAttribute("message", "出发或截止时间必须大于当前时间");
//				return "redirect:addShareProduct";
//			}
//			if (shareRentproduct.getFromdate().before( shareRentproduct.getEnddate())) {
//				redirectAttributes.addFlashAttribute("message", "截止时间不能小于出发时间");
//				return "redirect:addShareProduct?type=1";
//			}
//			//校验拼车总人数和车型核载人数
//			if (Integer.parseInt(shareRentproduct.getMinamount()) > tCargotype.getSeats()) {
//				redirectAttributes.addFlashAttribute("message", "拼车人数不能超过车辆核载人数");
//				return "redirect:addShareProduct?type=1";
//			}
//			String kms = mapkm;//地图测算的距离
//			double distance = 0.0;
//			int disLevel = 0;
//			if (StringUtils.isNotEmpty(kms)) {
//				if (kms.indexOf("公里")!=-1) {
//					distance = Double.parseDouble(kms.substring(0, kms.indexOf("公里")));
//					if (distance<=50&&distance>=0) {
//						disLevel = 1;
//					}else if (distance<=150&&distance>50) {
//						disLevel = 2;
//					}else if (distance<=275&&distance>150) {
//						disLevel = 3;
//					}else if (distance<=500&&distance>275) {
//						disLevel = 4;
//					}else {
//						disLevel = 5;
//					}
//				}else{
//					disLevel = 1;//距离太近,取不到公里数
//				}
//			}

//			TRentproduct tRentproduct =new TRentproduct();
//			tRentproduct.setProductname(productname);
//			tRentproduct.setAboardAddress(shareRentproduct.getBoardaddr());

//根据出发地,目的地 查询所有车型
//			Page<TCargotypeForsale> page = new Page<TCargotypeForsale>(request, response);
//			page.setPageSize(500);
//			cargotypeForsale.setPage(page);
//			List<TCargotypeForsale> cargotypeList = rentproductService.findAirCargotypeList(cargotypeForsale);
//			page.setList(cargotypeList);
//			List<Office> officeList = null;

//			TCargotypeForsale t=new TCargotypeForsale();
//			//根据车型获取对应的车队
//			if (cargotypeList.size()>0&&cargotypeList!=null) {
//				for (TCargotypeForsale tc : cargotypeList) {
//					if((tc.getCargotype().getCargotypeid()+"").equals(shareRentproduct.getCargotype())){
//					double condition0 = ((tc.getCargotype().getNudePrice()/2.00+100)+
//							(tc.getCargotype().getOilcost()+tc.getCargotype().getRoadmodules())*distance*2);
//					double condition1 = (tc.getCargotype().getNudePrice()+
//							(tc.getCargotype().getOilcost()+tc.getCargotype().getRoadmodules())*distance*2);
//					double condition2 = (((tc.getCargotype().getNudePrice()+300)*(distance/500+1))+
//							(tc.getCargotype().getOilcost()+tc.getCargotype().getRoadmodules())*distance*2);
//					Set<Double> priceSet = new TreeSet<Double>();
//					List<Double> priceList = new ArrayList<Double>();
//					tc.setDepartcity(depart);
//					tc.setDestcity(dest);
//					tc.setDisLevel(disLevel);//距离等级
//					officeList = rentproductService.findAirProductByType(tc);
//					if (officeList.size()>0&&officeList!=null) {
//						for (Office office : officeList) {
//							if (distance<=50&&distance>=0) {
//								office.setSuitrtnprice(Math.ceil(condition0*office.getFactor()));
//							}else if(distance<=500&&distance>50) {
//								office.setSuitrtnprice(Math.ceil(condition1*office.getFactor()));
//							}else {
//								office.setSuitrtnprice(Math.ceil(condition2*office.getFactor()));
//							}
//							}
//					}
//					tc.setOfficeList(officeList);
//					//取最低价
//					for (Office office : officeList) {
//						priceSet.add(office.getSuitrtnprice());
//					}
//					for (Double double1 : priceSet) {
//						priceList.add(double1);
//					}
//					if (priceList.size()>0) {
//						tc.setLowestAirPrice(priceList.get(0));
//					}
//					for(int z=0;z<tc.getOfficeList().size();z++){
//						if(tc.getOfficeList().get(z).getAbbr().equals(a.getAbbr())){
//							t=tc;
//						}
//					}
//					break;
//					}
//				}
//			}else{
//				redirectAttributes.addFlashAttribute("message", "未查询到数据");
//				return "redirect:allShareList";
//			}

//			if(t.getCargotype()==null){
//				redirectAttributes.addFlashAttribute("message", "没有对应车型");
//				return "redirect:addShareProduct?type=1";
//			}